package com.iseastar.dianxiaosan.home.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.iseastar.dianxiaosan.model.TradFinishBean;
import com.shouhuobao.station.R;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import droid.frame.activity.base.BaseAdapterWithImage;

public class TradeFinishAdapter extends BaseAdapterWithImage<TradFinishBean> {

	private SimpleDateFormat sdf;

	public TradeFinishAdapter(ArrayList<TradFinishBean> items, Activity context, ViewGroup viewGroup) {
		super(items, context, viewGroup);
		sdf = new SimpleDateFormat("yyyy-MM-dd");
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.trade_finish_item, parent, false);
			holder.code = (TextView) convertView.findViewById(R.id.trad_finish_code);
			holder.arriveTime = (TextView) convertView.findViewById(R.id.trade_fiish_store_time);
			holder.takeTime = (TextView) convertView.findViewById(R.id.trade_fiish_take_time);
			holder.img = (ImageView) convertView.findViewById(R.id.trad_finish_icon);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		TradFinishBean item = items.get(position);
		// set image
		showImage(item.getImageUrl(), holder.img, null);
		holder.code.setText("投递袋编号: " + item.getBagCode());
		Date date1 = new Date(item.getPostTime());
		String arriveTime = sdf.format(date1);
		holder.arriveTime.setText("到店时间: " + arriveTime);// 到店时间

		Date date2 = new Date(item.getPickTime());
		String takeTime = sdf.format(date2);
		holder.takeTime.setText("取走时间: " + takeTime);// 取走时间

		return convertView;
	}

	private static class ViewHolder {
		TextView code, arriveTime, takeTime;
		ImageView img;
	}

}
